const { DataTypes } = require('sequelize');

const seq = require('@db/sql');

const goods = require('../goods/goods.model');

const cart = seq.define(
  't_cart',
  {
    goods_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '商品id',
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '用户id',
    },
    number: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '商品数量',
    },
    selection: {
      type: DataTypes.ENUM(['0', '1']),
      allowNull: false,
      comment: '0: 未选择 1: 选中',
    },
  },
  {
    paranoid: true,
  }
);

cart.belongsTo(goods, { foreignKey: 'goods_id', as: 'goods' });

// cart.sync({ alter: true });

module.exports = cart;
